package com.example.controller;

import com.example.pojo.Emp;
import com.example.pojo.PageResult;
import com.example.pojo.Result;
import com.example.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: EmpController
 * Package: com.example.controller
 * Description:
 *
 * @Author liu
 * @Create 2025/5/25 21:03
 * @ Version 1.0
 */
@Slf4j
@RequestMapping("/emps")
@RestController

public class EmpController {

    @Autowired
    private EmpService empService;

    /**
     * 分页查询(原始方法)
     * Get
     * json格式
     * 增删改查 用Result封装
     * @RequestParam(defaultValue ="默认值") 用于设置参数默认值
     */
    @GetMapping
    public Result page(@RequestParam(defaultValue ="1") Integer page,@RequestParam(defaultValue = "10")  Integer pageSize){
        log.info("分页查询: page={},pagesize= {}", page,pageSize);
        PageResult pageResult = empService.page(page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 分页查询(推荐)
     * 使用PageHelper分页插件（mybasit框架）
     */
//    @GetMapping
//    public Result page(EmpQueryParam empQueryParam){
//        log.info("分页查询: {}", empQueryParam);
//        PageResult<Emp> pageResult = empService.page(empQueryParam);
//        return Result.success(pageResult);
//    }



}
